package com.aaa.service.impl;

import com.aaa.dao.StudentDao;
import com.aaa.entity.Student;
import com.aaa.service.StudentService;
import com.aaa.util.EntypeUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;
    @Override
    public PageInfo<Student> listAll(Integer pageNumber, Integer pageSize,String stuname,String status) {
        PageHelper.startPage(pageNumber,pageSize);
        List<Student> students = studentDao.listAll(stuname,status);
        PageInfo<Student> pageInfo=new PageInfo<>(students);
        return pageInfo;
    }

    @Override
    public Student getStuname(String stuname) {
        return studentDao.getStuname(stuname);
    }


    @Override
    public Integer insertOrUpdate(Student student) {
        Integer number=0;
        if (student.getId()==null){
            String encpassword = EntypeUtil.encpassword(student.getPassword(), student.getStuname());
            student.setPassword(encpassword);
            number= studentDao.insert(student);
        }else {
            number=studentDao.update(student);
        }
        return number;
    }

    @Override
    public Integer batchDelete(List<Student> students) {
        Integer integer=0;
        for (Student student : students) {
            integer = studentDao.batchDelete(student.getId());
        }
        return integer;
    }

    @Override
    public List<Student> selectRemark(Integer id) {
        return studentDao.selectRemark(id);
    }


}
